Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create a superfluous index for FK that is PK #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

semifor
Copy link

@semifor semifor commented May 22, 2015

If the primary key is also a foreign key, there's no need to create an
index for it, because the primary key constraint will suffice.

If the primary key is also a foreign key, there's no need to create an
index for it, because the primary key constraint will suffice.
# Get the primary key, if there is one. No need to create an index for an
# FK that is also the PK. It may be a multi-field key, so generate a
# suitable string for comparison.
my $pk = join "\0", map $_->fields, grep $_->type eq PRIMARY_KEY, @constraints;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you're joining all the fields in the primary key, but below you're testing that against the first field in the foreign key, so this can't work at all for composite primary keys.

I don't know if the current handling is actually correct for compound indexes and foreign keys, but either way, I think primary keys should be handled the same as normal indexes (i.e. just add each field to %indexed_fields).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Looks like the code in master doesn't handle multi-column foreign keys, either. I'll update the PR incorporating your suggestion and fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants